/************************************************************************
Copyright 2003, 2004, 2005, 2006, 2007, 2008 Grid Technology Research Center,
National Institute of Advanced Industrial Science and Technology.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
************************************************************************/

package jp.aist.gtrc.plus.scheduler.node;

import java.util.Locale;

import jp.aist.gtrc.plus.scheduler.status.NodeStatus;

class PhysicalNodeInfo {

	private transient NodeStatus status;
	private transient NodeResource resource;
	private int lauchProcNum;
	private static final int DEFAULT_LAUNCE_PROC_NUM = 1;

	protected PhysicalNodeInfo(NodeStatus status){

		update(status);

	}

	final void update(NodeStatus status){

		assert(status != null);
		boolean updateRsc = ((this.status == null) || (!this.status.isAlive() && status.isAlive()));

		this.status = status;
		if (updateRsc) {
			// update at first time or when node is starting up now
			this.resource = status.getResource();
		}
		setLaunceProcessNum(DEFAULT_LAUNCE_PROC_NUM);

	}

	public NodeStatus getStatus() {

		return status;

	}

	public NodeResource getResource() {

		return resource;

	}

	public String getName() {

		return getStatus().getName();

	}

	public final void setLaunceProcessNum(int procNum) {

		this.lauchProcNum = procNum;

	}

	public final int getLaunchProcessNum() {

		return lauchProcNum;

	}

	public String toString() {

		return String.format(Locale.US, "status=%s, resource=%s, launchProcNum=%d, ",
				status.toString(), resource.toString(), lauchProcNum);

	}
}
